#!~/.jumbo/bin/python3
# coding: utf-8


import subprocess
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
                    datefmt='%a, %d %b %Y %H:%M:%S')


class bk_h5_app_access:

    def __init__(self):

        self.pid_num = "df -h |grep home|awk '{print$5}'|awk -F '%' '{print$1}'"

    def backup(self):

        # 通过查看进程号判断服务是否挂
        if int(subprocess.getoutput(self.pid_num)) < 88:
            logging.info("磁盘资源 is enough!")

        else:
            subprocess.call('curl -H "content-type:application/json" -X POST -d \'{"receiver": "10086",'
                            '"templateName": "EMPTY_HI_TEMPLATE","msgVariable": {"content": "ip磁盘资源使用超过' + subprocess.getoutput(
                self.pid_num) + '% ! Please check !"}}\' '
                            'http://域名:1100/services/notify', shell=True)

            logging.info("磁盘资源超过{}% ! Please check !".format(subprocess.getoutput(self.pid_num)))


if __name__ == '__main__':
    bhaa = bk_h5_app_access()
    bhaa.backup()

